$(function(){
	getDayNum();
	initExport();
});



//"每天"按钮
$("#everyDay").click(function(){
	everyWeekDisabled();
});

//"每周"按钮
$("#everyWeek").click(function(){
	everyWeekEnable();
});

//为选择天数绑定下拉项
function getDayNum(){
	for(var i=2;i<=30;i++){
		$("<option value= "+i+">"+i+"</option>").appendTo("#dayNum");
	}
};


//使everyWeek多选框变为不可用
function everyWeekDisabled(){
	var items = document.getElementsByName("selectWeekDay");
    for(var i=0;i<items.length;i++){
	    items[i].disabled=true;
	   }
}

//使everyWeek多选框变为可用
function everyWeekEnable(){
	var items = document.getElementsByName("selectWeekDay");
    for(var i=0;i<items.length;i++){
	    items[i].disabled="";
	   }
}


function initExport(){
	$.ajax({
		type:'post',
		dataType:'json',
		url:contextPath+'/exportset/getExportValue.control',
		success:getSucc,
		error:getError
	});
}

//获取用户设置的信息
function getSucc(json){
	debugger;
	var id = json.exportSetVO.id;
	var logType = json.exportSetVO.logType;
	var date = json.exportSetVO.date;
	var everyDayOrWeekFlag = json.exportSetVO.everyDayOrWeekFlag;
	var weekSign = json.exportSetVO.weekSign;
	var startTime = json.exportSetVO.startTime;
	$("#id").val(id);
	if(logType!=null&&logType!=""){
		var logTypeArray =  logType.split(',');
		for(var i=0;i<logTypeArray.length;i++){
			$("#"+logTypeArray[i]).attr('checked',true);
		}
	}
	$("#dayNum").val(date);
	if(everyDayOrWeekFlag==1||everyDayOrWeekFlag==null){
		$("#everyDay").attr('checked',true);
		everyWeekDisabled();
	}else{
		$("#everyWeek").attr('checked',true);
	}
	if(weekSign!=null&&weekSign!=""){
		var weekSignArray =  weekSign.split(',');
		for(var i=0;i<weekSignArray.length;i++){
			$("#week"+weekSignArray[i]).attr('checked',true);
		}
	}
	$("#startTime").val(startTime);
}

function getError(){
	
}


$("#btn_Save").button().click(function(){
	debugger;
	var id = $("#id").val();
	var logType = "";
	$("input:checked[name='selectLog']").each(function(){
		 logType += $(this).val()+",";
	});
	var date = $("#dayNum").val();
	everyDayOrWeekFlag = $("input:checked[name='selectTime']").val();
	var weekSign = "";
	$("input:checked[name='selectWeekDay']").each(function(){
		weekSign += $(this).val()+",";
	});
	var startTime = $("#startTime").val();
	$.ajax({
		type:'post',
		dataType:'json',
		data:{
			"id":id,
			"logType":logType,
			"date":date,
			"everyDayOrWeekFlag": everyDayOrWeekFlag,
			"startTime":startTime,
			"weekSign":weekSign,
		},
		url:contextPath+'/exportset/save.control',
		success:saveSucc,
		error:saveError
	});
});


function saveSucc(){
	alert('保存成功！');
}

function saveError(){
	alert('保存失败！');
}

